package app.kotlin_1.adapter

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import app.kotlin_1.R
import app.kotlin_1.activity.GameKindActivit
import app.kotlin_1.bean.GameKindBean
import app.kotlin_1.utils.toast
import kotlinx.android.synthetic.main.item_drawerlayout_game_kind.view.*

/**
 * Created by 刘智强 on 2017/9/20.
 * 侧滑栏的列表适配器
 */
class HomeDrawerLayoutAdapter : RecyclerView.Adapter<HomeDrawerLayoutAdapter.ItemViewHolder> {
    private var context: Activity? = null
    private var gameKindList: MutableList<GameKindBean>? = null

    constructor(context: Activity?, gameKindList: MutableList<GameKindBean>?) : super() {
        this.context = context
        this.gameKindList = gameKindList
    }

    override fun onBindViewHolder(holder: ItemViewHolder?, position: Int) {
        var name:String=gameKindList!!.get(position).name!!
        holder!!.itemView.ivKindIcon.setImageResource(gameKindList!!.get(position)!!.iconId!!)
        holder!!.itemView.tvKindName.text = name
        holder!!.itemView.rlItem.setOnClickListener { v ->
            val intent=Intent(context,GameKindActivit::class.java)
            val bundle=Bundle()
            bundle!!.putString("title",name)
            intent.putExtras(bundle)
            context!!.startActivity(intent)
        }

    }

    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ItemViewHolder {

        return ItemViewHolder(LayoutInflater.from(context).inflate(R.layout.item_drawerlayout_game_kind, parent, false))
    }

    override fun getItemCount(): Int {
        return gameKindList!!.size
    }

    inner class ItemViewHolder : RecyclerView.ViewHolder {
        constructor(itemView: View?) : super(itemView)
    }
}